package com.arpa.oms.controller;

import com.arpa.core.web.Result;
import com.arpa.ntocc.common.common.Page;
import com.arpa.ntocc.common.common.constant.StrConsts;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.ntocc.common.security.annotation.NeedLogin;
import com.arpa.oms.domain.dto.OmsInventoryDTO;
import com.arpa.oms.domain.vo.OmsInventoryVO;
import com.arpa.oms.service.IOmsInventoryService;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Api(tags = "OMS库存")
@RestController
@RequestMapping(value = "/oms/OmsInventory", produces = "application/json;charset=UTF-8")
@Log4j2(topic = "business")
public class OmsInventoryController {

    private final IOmsInventoryService  omsInventoryService;

    public OmsInventoryController(IOmsInventoryService omsInventoryService) {
        this.omsInventoryService = omsInventoryService;
    }

    /**
     * OMS采购单列表
     *
     * @param dto
     * @param request
     * @return
     */
    @ApiOperation(value = "OMS库存列表", notes = "OMS库存列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "授权token", required = true, paramType = "header", dataType = "String", defaultValue = "Bearer "),
            @ApiImplicitParam(name = "deviceId", value = "设备id", paramType = "header", dataType = "string", defaultValue = "0000000000"),
    })
    @ApiResponses(@ApiResponse(code = 0, message = "success", response = OmsInventoryVO.class))
    @NeedLogin
    @GetMapping()
    public Result list(OmsInventoryDTO dto, HttpServletRequest request) {
        try {
            dto.setShipmentCode(UserUtil.getLoginWarehouseCodeOrShipmentCode());
            dto.setWarehouseCodes(UserUtil.getShipmentAuthorizeWarehouseCodes());

            OmsInventoryVO omsInventoryVO=omsInventoryService.queryListSum(dto);
            List<OmsInventoryVO> omsInventoryVoList = omsInventoryService.queryList(dto);
            Page returnPage = new Page(dto.getPageNum(), dto.getPageSize());
            returnPage.setRecords(omsInventoryVoList);
            returnPage.setTotal(omsInventoryVO.getTotal());
            returnPage.setSumObject(omsInventoryVO);
            return Result.ok().data(returnPage);
        } catch (Exception e) {
            log.error(StrConsts.CATCH_MESSAGE,e);
            return Result.error(e.getMessage());
        }
    }










}
